package com.hexuan.controller;


import com.hexuan.pojo.Dept;
import com.hexuan.pojo.Result;
import com.hexuan.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
public class DeptController {

    @Autowired
    private DeptService deptService;


    /*
    * 查询部门
    * */
    @GetMapping("/depts")
    public Result list(){
        log.info("查询全部部门数据");
        List<Dept> deptList = deptService.list();
        return Result.success(deptList);
    }
    /*
    * 删除部门
    * */
    @DeleteMapping("/depts/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("根据id删除部门");
        deptService.delete(id);//删除部门

        return Result.success();
    }

    /**
     * 添加部门
     */
    @PostMapping("/depts")
    public Result add(@RequestBody Dept dept){
        log.info("新增部门{}" , dept);
        deptService.add(dept);

        return Result.success();
    }
    /**
     * 根据id查询部门
     */
    @GetMapping("/depts/{id}")
    public Result queryById(@PathVariable Integer id){
        log.info("根据id查询部门");
        Dept dept = deptService.queryByid(id);

        return Result.success(dept);
    }
    /**
     * 修改部门信息
     */
    @PutMapping("/depts")
    public Result modifyDept(@RequestBody Dept dept){
        log.info("修改部门信息{}",dept);
        deptService.modifyDept(dept);
        return Result.success();
    }

}
